package com.ruoyi.daily.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.daily.domain.dto.FulfillmentRateDto;
import com.ruoyi.daily.domain.dto.NotMeetingStandardsDto;
import com.ruoyi.daily.domain.dto.ThreeClaimsDto;
import com.ruoyi.daily.mapper.QualityReportTowMapper;
import com.ruoyi.daily.service.QualityReportTowService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author cmz
 * @Date 2024-06-14 19:09
 */
@Service
public class QualityReportTowServiceImpl implements QualityReportTowService {
    @Resource
    private QualityReportTowMapper qualityReportTowMapper;
    @Override
    public R<List<NotMeetingStandardsDto>> notMeetingStandards() {
        List<NotMeetingStandardsDto> l = qualityReportTowMapper.notMeetingStandards();
        return R.ok(l);
    }

    @Override
    public R<List<ThreeClaimsDto>> threeClaims() {
        List<ThreeClaimsDto> l = qualityReportTowMapper.threeClaims();
        return R.ok(l);
    }

    @Override
    public R<FulfillmentRateDto> fulfillmentRate() {
        FulfillmentRateDto fulfillmentRateDto = qualityReportTowMapper.fulfillmentRate();
        return R.ok(fulfillmentRateDto);
    }

    @Override
    public R<Map<String, Object>> threeClaimsEcharts() {
        List<ThreeClaimsDto> data = this.threeClaims().getData();
        Map<String, Object> arrayDto = new HashMap<>();
        
        List<String> name = new ArrayList<>();
        
        List<Integer> delayQuantity = new ArrayList<>();
        List<Integer> lostQuantity = new ArrayList<>();
        List<Integer> damageQuantity = new ArrayList<>();
        List<Double> delayAmount = new ArrayList<>();
        List<Double> lostAmount = new ArrayList<>();
        List<Double> damageAmount = new ArrayList<>();
        for (ThreeClaimsDto datum : data) {
            name.add(datum.getName());
            delayQuantity.add(datum.getDelayQuantity());
            lostQuantity.add(datum.getLostQuantity());
            damageQuantity.add(datum.getDamageQuantity());
            delayAmount.add(datum.getDelayAmount());
            lostAmount.add(datum.getLostAmount());
            damageAmount.add(datum.getDamageAmount());
        }

        List<Map<String,Object>> list = new ArrayList<>();
        Map<String,Object> nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","延误量");
        nameTimelinessRate.put("values",delayQuantity);
        nameTimelinessRate.put("type","line");
        nameTimelinessRate.put("yAxisIndex",1);
        list.add(nameTimelinessRate);

        nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","遗失量");
        nameTimelinessRate.put("values",lostQuantity);
        nameTimelinessRate.put("type","line");
        nameTimelinessRate.put("yAxisIndex",2);
        list.add(nameTimelinessRate);

        nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","破损量");
        nameTimelinessRate.put("values",damageQuantity);
        nameTimelinessRate.put("type","line");
        nameTimelinessRate.put("yAxisIndex",3);
        list.add(nameTimelinessRate);

        nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","延误赔款金额");
        nameTimelinessRate.put("values",delayAmount);
        nameTimelinessRate.put("type","bar");
        nameTimelinessRate.put("stack","bar");
        list.add(nameTimelinessRate);

        nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","遗失赔款金额");
        nameTimelinessRate.put("values",lostAmount);
        nameTimelinessRate.put("type","bar");
        nameTimelinessRate.put("stack","bar2");
        list.add(nameTimelinessRate);

        nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","破损赔款金额");
        nameTimelinessRate.put("values",damageAmount);
        nameTimelinessRate.put("type","bar");
        nameTimelinessRate.put("stack","bar3");
        list.add(nameTimelinessRate);
        

        List<Map<String,Object>> yAxis = new ArrayList<>();
        HashMap<String, Object> yAxisMap1 = new HashMap<>();
        yAxisMap1.put("type","value");
        yAxisMap1.put("name","单位: 元");
        HashMap<String, Object> axisLabel = new HashMap<>();
        axisLabel.put("formatter","{value}");
        yAxisMap1.put("axisLabel",axisLabel);
        yAxis.add(yAxisMap1);

        yAxisMap1 = new HashMap<>();
        yAxisMap1.put("type","value");
        yAxisMap1.put("name","单位:件");
        axisLabel = new HashMap<>();
        axisLabel.put("formatter","{value} %");
        yAxisMap1.put("axisLabel",axisLabel);
        yAxis.add(yAxisMap1);

        arrayDto.put("dateStrs",name);
        arrayDto.put("nameAndListValueDtos",list);
        arrayDto.put("yAxis",yAxis);

        return R.ok(arrayDto);
    }

    @Override
    public R<Map<String, Object>> notMeetingStandardsEcharts() {
        List<NotMeetingStandardsDto> data = this.notMeetingStandards().getData();
        Map<String, Object> arrayDto = new HashMap<>();
        
        List<String> name = new ArrayList<>();
        List<Integer> shouldSignCount = new ArrayList<>();
        List<Integer> frequencyDeadCount = new ArrayList<>();
        List<Integer> untimelyCount = new ArrayList<>();
        for (NotMeetingStandardsDto datum : data) {
            name.add(datum.getName());
            shouldSignCount.add(datum.getShouldSignCount());
            frequencyDeadCount.add(datum.getFrequencyDeadCount());
            untimelyCount.add(datum.getUntimelyCount());
        }
        List<Map<String,Object>> list = new ArrayList<>();
        Map<String,Object> nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","目标值应答量");
        nameTimelinessRate.put("values",shouldSignCount);
        nameTimelinessRate.put("type","bar");
        list.add(nameTimelinessRate);

        nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","实际签收量");
        nameTimelinessRate.put("values",frequencyDeadCount);
        nameTimelinessRate.put("type","bar");
        list.add(nameTimelinessRate);

        nameTimelinessRate = new HashMap<>();
        nameTimelinessRate.put("name","未按时应签量");
        nameTimelinessRate.put("values",untimelyCount);
        nameTimelinessRate.put("type","bar");
        list.add(nameTimelinessRate);

        List<Map<String,Object>> yAxis = new ArrayList<>();
        HashMap<String, Object> yAxisMap1 = new HashMap<>();
        yAxisMap1.put("type","value");
        yAxisMap1.put("name","单位: 元");
        HashMap<String, Object> axisLabel = new HashMap<>();
        axisLabel.put("formatter","{value}");
        yAxisMap1.put("axisLabel",axisLabel);
        yAxis.add(yAxisMap1);

        arrayDto.put("dateStrs",name);
        arrayDto.put("nameAndListValueDtos",list);
        arrayDto.put("yAxis",yAxis);

        return R.ok(arrayDto);
    }

    @Override
    public R<ThreeClaimsDto> threeClaimsOne() {
        
        return null;
    }
}
